﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using helloworld2;
using helloworld2.MODEL;

namespace helloworld2
{
    class Station
    {

        List<Road> connections = new List<Road>();
        List<KeyValuePair<int, int>> field;
        public int id { get; set; }
        public double length { get; set; }
        public KeyValuePair<int, int> center { get; set; }

        public Station(int id, List<KeyValuePair<int, int>> field, KeyValuePair<int, int> center)
        {
            this.id = id;
            this.field = field;
            this.center = center;
            this.length = findLength();
            Edge e = new Edge(this.id, 3*1.2, true);
        }

        public Station()
        {
        }

        public List<KeyValuePair<int, int>> getField()
        {
            var newField = new List<KeyValuePair<int, int>>();
            foreach (KeyValuePair<int, int> kp in field)
            {
                newField.Add(kp);
            }
            return newField;
        }

        public bool lookForCoordinates(KeyValuePair<int, int> coordinates)
        {
            bool re = false;
            if (field.Contains(coordinates))
            {
                re = true;
            }
            return re;
        }

        private double findLength()
        {
            KeyValuePair<int, int> start = this.field[0];
            KeyValuePair<int, int> end = this.field[field.Count-1];

            double a;
            double b;

            if (start.Value > end.Value)
            {
                a = start.Value - end.Value;
            }

            else
            {
                a = end.Value - start.Value;
            }

            if (start.Key > end.Key)
            {
                b = start.Key - end.Key;
            }

            else
            {
                b = end.Key - start.Key;
            }
            
            double result = Math.Sqrt(Math.Pow(a, 2) + Math.Pow(b, 2));
            result = result * 1.2;

            return result;
        }

        public List<Road> getConnection()
        {
            List<Road> recon = new List<Road>();
            foreach (Road r in connections)
            {
                recon.Add(r);
            }
            return recon;
        }

        public void addConnection(Road r)
        {
            Console.WriteLine("Added one road to station");
            connections.Add(r);
        }

    }
}